#!/bin/bash

# Rosetta Stone Package Manager
# originally developed as part of witch 
# https://github.com/Digit/witch/issues/18
#~ now hacking to be stand alone
# https://notabug.org/digit/rspm

#this is still just doodling around a proof of concept
#put this file in your $PATH somewhere (like /bin/rspm)
#make this executable (like sudo chmod +x /bin/rspm)
#run it. (like rspm update && rspm install tmux)

##################################################
#set your package manager here

#as part of witch:
#PACKAGEMGR=$(sed -n '4p' $WITCH/config.base.txt)

#stand alone:
#PACKAGEMGR=APTGET

#used in bedrock:
#PACKAGEMANAGER=${insert fancy script here}
#and also now that pmm is a thing, consider wrapping for it too!  :D
##################################################


#basics first. AFTER we get these, we can futz over the finer grained nuanced commands.
#install
#remove
#update
#upgrade
#search

case $PACKAGEMGR in
  "PORTAGE") #like in gentoo
    case $1 in
      "install") emerge $2 ;;
      "remove") emerge -C $2 ;;
      "update") emerge --sync ;;
      "upgrade") emerge -DuN ;;
      "search")
        if [ $eix == "true" ]; then #FIXME
          eix $2
        else
          emerge --search $2
        fi
      ;;
    esac
  ;;
  
  "PALUDIS") #like in exherbo
    case $1 in
      "install") cave resolve -x $2 ;;
      "remove") cave resolve -Px $2 ;; # ~ er, i've forgotten the paludis commands.  ...
      "update") cave sync ;;
      "upgrade") cave resolve world -x ;;
      "search") cave search $2 ;;
    esac
    # etc
  ;;
  
  "APTGET") #like in devuan
    case $1 in
      "install") apt-get install $2 ;;
      "remove") apt-get remove $2 ;;
      "update") apt-get update ;;
      "upgrade") apt-get upgrade ;;
      "search") apt-cache search $2 ;;
    esac
  ;;
  
  "SLAPTGET") #like in slackware?
    case $1 in
      "install") slapt-get install $2 ;;
      "remove") slapt-get remove $2 ;;
      "update") slapt-get update ;;
      "upgrade") slapt-get upgrade ;;
      "search") slapt-cache search $2 ;; #that right?? FIXME
    esac
  ;;
  
  "XBPS") #like in voidlinux
    case $1 in
      "install") xbps-install $2 ;;
      "remove") xbps-remove $2 ;;
      "update") xbps-install -S ;;
      "upgrade") xbps-install -Su ;;
      "search") xbps-query -Rs $2 ;;
    esac
  ;;
    
  "PACMAN") #like in archlinux
    case $1 in
      "install") pacman -S $2 ;;
      "remove") pacman -Rc $2 ;;
      "update") pacman -Sy ;;
      "upgrade") pacman -Syu ;;
      "search") pacman -Ss $2 ;;
    esac
  ;;

#this segment could do with a double if check, or something.  
#  "AUR") #like in archlinux  
  "YAY") #like in archlinux
    case $1 in
      "install") yay -S $2 ;;
      "remove") yay -R $2 ;;
      "update") yay -Sy ;;
      "upgrade") yay -Sua ;;
      "search") yay -Ss $2 ;;
    esac
  ;;
  
  "ZYPPER") #like in suse
    case $1 in
      "install") zypper in $2 ;;
      "remove") zypper rm $2 ;;
      "update") zypper ref ;;
      "upgrade") zypper up ;;
      "search") zypper se $2 ;;
    esac
  ;;
  
  "GUIX") #like in guixsd
    case $1 in
      "install") guix package -i $2 ;;
      "remove") guix package -r $2 ;;
      "update") guix pull ;;
      "upgrade") guix package -u $2 ;;
      "search") guix package -s $2 ;;
    esac
  ;;
  
  "CPT") #like in carbs
    case $1 in
	#      "install") cpt-build $2 ; cpt-install $2 ;;
      "install") cpt bi $2 ;;
      "remove") cpt-remove $2 ;;
      "update") cpt-update -0 ;; #as of cpt >v5.0 
      "upgrade") cpt-update -n ;; #cpt-update (no options) updates&upgrades.
      "search") cpt-search $2 ;;
    esac
  ;;
  
  "APK") #like in alpine https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management
    case $1 in
      "install") apk add $2 ;;
      "remove") apk del $2 ;;
      "update") apk update ;;
      "upgrade") apk upgrade ;;
      "search") apk search $2 ;;
    esac
  ;;
  
  
  "SCRATCH") #like in venom https://venomlinux.org/wiki#package-manager.introduction
    case $1 in
      "install") scratch install $2 ;;
#      "remove") scratch remove $2 ;;
      "remove") scratch purge $2 ;; #and orphaned dependancies
      "update") scratch sync ;;
#      "upgrade") scratch upgrade ;;
      "upgrade") scratch sysup ;; #full
      "search") scratch search $2 ;;
    esac
  ;;

# may need several of these to meet each type set in pmm?  doing just apt style for now  
  "PMM") #like in bedrock   (lol! pmm rather supercedes rspm, but ok)
    case $1 in
      "install") pmm install $2 ;;
      "remove") pmm remove $2 ;;
      "update") pmm update ;;
      "upgrade") pmm upgrade $2 ;;
      "search") pmm search $2 ;;
    esac
  ;;
esac

# ^ something like that.   basic jist.   now clean up, and repeat for other package managers.
# feel free to come up with a better way... this is just an initial jotting down of the concept... not clean code.  SO LETS NOT PUT rspm COMMANDS ANYWHERE UNTIL IT IS REAL WORKING CODE.  ;)


